package scala.pattern

/**
 * 扩展案例
 */
object GenericTest {
  def main(args: Array[String]): Unit = {
    // 特殊的模式匹配1，打印元组第一个元素
    for (elem <- Array(("a", 1), ("b", 2), ("c", 3))) {
      println(elem._1)
    }
    for ((s,i) <- Array(("q", 12), ("w", 12), ("e", 31))) println(s +":"+i)
    for ((s,_) <- Array(("q", 12), ("w", 12), ("e", 31))) println(s)
    for (("a",count)<- Array(("q", 12), ("w", 12), ("e", 31))) println(count)

    println("-------------")


    // 特殊的模式匹配2，给元组元素命名
    var (id,name,age): (Int,String,Int) =(100,"试试",1)
    println((id,name,age))

    // 特殊的模式匹配3，遍历集合中的元组，给count * 2
    val list: List[(String,Int)] = List(("a",1),("ac",12),("a22",111))
    println(list.map{
      case (s,i)=> (s,i*2)
    })

    val list1 = List(("a", ("a", 1)), ("b", ("b", 2)), ("c", ("c", 3)))
    println(list1.map{
      case (k,(s,i))=>(s,i*7)
    })


  }
}
